﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class ParentBLL : IParentBLL
    {
        private static readonly IParentDAL dal = DataAccess.CreateParents();

        private ParentInfo paInfo = new ParentInfo();
        private EmployeeInfo empInfo = new EmployeeInfo();
        private MasNamePrefixInfo prefixInfo = new MasNamePrefixInfo();
        private PersonInfo perInfo = new PersonInfo();

        public IList<ParentInfo> ListParents(string Employee)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            paInfo.Employee = empInfo;
            return dal.ListParents(paInfo);
        }
        public IList<ParentInfo> ListParentsBySequence(int Sequence)
        {
            return dal.ListParents(new ParentInfo(Sequence));
        }

        public void Insert(string Employee, string Prefixes, string FirstName, string LastName, string Citizen
            , Nullable<DateTime> BirthDate, string Type, string Status, bool CareStatus, int CreatedBy)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            prefixInfo.Sequence = Prefixes.Length > 0 ? Int32.Parse(Prefixes) : 0;
            perInfo.NamePrefix = prefixInfo;
            perInfo.FirstName = FirstName;
            perInfo.LastName = LastName;
            perInfo.BirthDate = BirthDate;
            perInfo.Citizen = Citizen;

            try
            {
                dal.Insert(new ParentInfo(0, empInfo, perInfo, Type, "", CareStatus, Status
                    , "", "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string Employee, string Prefixes, string FirstName, string LastName
            , string Citizen, Nullable<DateTime> BirthDate, string Type, string Status, bool CareStatus, int UpdatedBy)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            prefixInfo.Sequence = Prefixes.Length > 0 ? Int32.Parse(Prefixes) : 0;
            perInfo.NamePrefix = prefixInfo;
            perInfo.FirstName = FirstName;
            perInfo.LastName = LastName;
            perInfo.BirthDate = BirthDate;
            perInfo.Citizen = Citizen;

            try
            {
                dal.Update(new ParentInfo(Sequence, empInfo, perInfo, Type, "", CareStatus, Status
                    , "", "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
